﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace QL_DonDatHang
{
    public partial class frm_ThanhToan : MaterialSkin.Controls.MaterialForm 
    {
        

        /// <summary>
        /// 
        /// </summary>
        #region ThuocTinh
        
        
        private string messeger;
        Program_DDH pgram;
        public string Messeger
        {
            get
            {
                return messeger;
            }

            set
            {
                messeger = value;
            }
        }

        public int IdSender
        {
            get
            {
                return idSender;
            }

            set
            {
                idSender = value;
            }
        }

        private int idSender;

        #endregion
        /// <summary>
        /// 
        /// </summary>
        public frm_ThanhToan(int id)
        {
            InitializeComponent();
            this.IdSender = id;
            pgram = new Program_DDH();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="messeger"></param>
        #region KhoiTao
        
        #endregion
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        #region PhuongThuc
        private void frm_ThanhToan_Load(object sender, EventArgs e)
        {
            loadThongTin();
        }
        private void loadThongTin()
        {
            if (pgram.slect_ThanhToan(IdSender).Rows.Count==0)
                return;
            ht_tenKH.Text = pgram.slect_ThanhToan(IdSender).Rows[0][0].ToString().Trim();
            ht_tenSP.Text = pgram.slect_ThanhToan(IdSender).Rows[0][1].ToString().Trim();
            ht_SoLuong.Text = pgram.slect_ThanhToan(IdSender).Rows[0][2].ToString().Trim();
            ht_DonGia.Text = pgram.slect_ThanhToan(IdSender).Rows[0][3].ToString().Trim() + " VND";
            ht_tongtien.Text = pgram.slect_ThanhToan(IdSender).Rows[0][4].ToString().Trim()+" VND";
        }
        
        private void btn_Pay_Click(object sender, EventArgs e)
        {
            try
            {
                if (MessageBox.Show("Xác nhận thanh toán ", "Thông báo ", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (pgram.XoaDonHang(IdSender))
                    {
                        MessageBox.Show("Thanh toán thành công! ", "Thông báo");
                        this.Close();
                    }
                    else
                    {
                        MessageBox.Show("Thanh toán không thành công! ", "Thông báo");
                    }
                }
            }catch(Exception ex)
            {
                MessageBox.Show("Không thể thanh toán! ", "Error", MessageBoxButtons.OK,MessageBoxIcon.Error);
            }

        }
        #endregion

        private void btn_Back_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
